package com.wuyb.util;

import com.wuyb.pojo.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 从认证上下文获取用户信息
 *
 * @Author: wyb
 * @Date: 2024/01/02/12:04
 * @Description:
 */
public class MyUtil {

    public static User getUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null) {
            return null;
        }
        return (User) authentication.getPrincipal();
    }

}
